package jvm;
/*
指令重排序案例分析
 */
import java.util.concurrent.TimeUnit;

public class Test09 {
    public static void main(String[] args) {
        MyCompare myCompare = new MyCompare();

            new Thread(() -> {
                    //线程要执行的代码
                myCompare.x = myCompare.x;
                try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); }
                myCompare.b = 1;
                System.out.println("x = " + myCompare.x);
                 },"AAAA").start();
                new Thread(() -> {
                        //线程要执行的代码
                    myCompare.y = myCompare.b;
                    myCompare.a = 2;
                    System.out.println("y = " + myCompare.y);
                     },"AAAA").start();

        System.out.println("x = " + myCompare.x + "y = " + myCompare.y);
    }
}

class MyCompare {
    int a,b,x,y = 0;

}